package cn.schedule.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.schedule.dto.Pager;


@Controller
@RequestMapping("/player/*")
public class PlayerController {
    
	/**
	 * 分页查询页面
	 */
	@RequestMapping("findPageList")
	public String findPageList(HttpServletRequest req, HttpServletResponse res, ModelMap model/*, MgtUser mgtUser, Pager page*/) {
		// String sortColumns = "AddTime DESC";// 手动自定排序字段 排序方式
//		mgtUser.setSortColumns("AddTime DESC");
//		Pager pager = mgtUserService.findPageList(mgtUser, page.getPageNumber(), page.getPageSize());
		/**测试用*/
		Pager pager = new Pager();
		pager.setTotal(5);
		pager.setPageNumber(1);
		pager.setPageSize(10);
		//获取当前登录用户的userId，用以判断当前操作员不能删除自己
		String currentUserId = (String) req.getSession().getAttribute("mgtUserId");
		model.put("currentUser", currentUserId);
//		model.put("pager", pager);
		return "player/playerList";
	}
	
	/**
	 * 新增
	 */
	@RequestMapping("playerAdd.html")
	public String playerAdd(HttpServletRequest req, HttpServletResponse res, ModelMap model/*, MgtUser mgtUser, Pager page*/) {
		// String sortColumns = "AddTime DESC";// 手动自定排序字段 排序方式
//		mgtUser.setSortColumns("AddTime DESC");
//		Pager pager = mgtUserService.findPageList(mgtUser, page.getPageNumber(), page.getPageSize());
		//获取当前登录用户的userId，用以判断当前操作员不能删除自己
		String currentUserId = (String) req.getSession().getAttribute("mgtUserId");
		model.put("currentUser", currentUserId);
//		model.put("pager", pager);
		return "player/playerAdd";
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("playerSave")
	public String playerSave(HttpServletRequest req, HttpServletResponse res, ModelMap model/*, MgtUser mgtUser, Pager page*/,final RedirectAttributes redirectAttributes) {
		// String sortColumns = "AddTime DESC";// 手动自定排序字段 排序方式
//		mgtUser.setSortColumns("AddTime DESC");
//		Pager pager = mgtUserService.findPageList(mgtUser, page.getPageNumber(), page.getPageSize());
		//获取当前登录用户的userId，用以判断当前操作员不能删除自己
		String currentUserId = (String) req.getSession().getAttribute("mgtUserId");
		model.put("currentUser", currentUserId);
//		redirectAttributes.addFlashAttribute("message", msg);
		return "redirect:/agentUser/agentList.html";
	}
}
